<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/public/header.jsp"%>

<html>
<head>
  <title>工程项目管理信息系统</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
.STYLE1 {
	font-size: 11pt;
	font-weight: bold;
}
BODY {
		background-image: URL(<%=contextPath %>/public/images/mail.jpg);
		background-position: center;
		background-repeat: no-repeat;
		background-attachment: fixed;
		margin:0 auto; width:500px;
		}
</style>

<script type="text/javascript">
	function checkUserName(inputStr) {
	  var tmpValue = inputStr;
	  //以下搜索字符串中的特殊字符，如果存在，则替换成""
	  if (tmpValue.indexOf('|') > -1) {return false; }
	  if (tmpValue.indexOf('&') > -1) {return false; }
	  if (tmpValue.indexOf(';') > -1) {return false; }
	  if (tmpValue.indexOf('$') > -1) {return false; }
	  if (tmpValue.indexOf('%') > -1) {return false; }
	  if (tmpValue.indexOf('@') > -1) {return false; }
	  if (tmpValue.indexOf("'") > -1) {return false; }
	  if (tmpValue.indexOf('"') > -1) {return false; }
	  if (tmpValue.indexOf('(') > -1) {return false; }
	  if (tmpValue.indexOf(')') > -1) {return false; }
	  if (tmpValue.indexOf('+') > -1) {return false; }
	  if (tmpValue.indexOf('<') > -1) {return false; }
	  if (tmpValue.indexOf('>') > -1) {return false; }
	  if (tmpValue.indexOf('--') > -1) {return false; }
	  if (tmpValue.indexOf(",") > -1) {return false; }
	  if (tmpValue.indexOf("?") > -1) {return false; }
	  if (tmpValue.indexOf("=") > -1) {return false; }
	  if (tmpValue.indexOf("\\") > -1) {return false; }
	  if (tmpValue.indexOf("\n") > -1) {return false; }
	  if (tmpValue.indexOf("\r") > -1) {return false; }
	 return true;
	}
	function doLogin(){
	    if($('#userName').val() == "" || $('#userName').val() == null){
	      alert("请输入用户名");
	      $('#userName').focus();
	      return ;
	    }
	    if (!checkUserName($('#userName').val())) {
	      alert("输入的用户名含有特殊字符！请修改");
	      $('#userName').focus();
	      return;
	    }
	    loginNamePass();
	  }
	
	/**
	 * 用户名密码登录
	 */
	function loginNamePass() {
	  var userName = $('#userName').val();
	  var pwd = $('#pwd').val();
	  var para = "username="+userName+"&password="+pwd;
	  var url = "<%=contextPath %>/springMVC/core/doLogin";
	  try {
		  $.ajax({
				type:'POST',
				url:url,
				data:para,
				success:function(json){
			  		if (json.rtState == "0"){
			  			setCookie('userName',$('#userName').val());
			  			var url = "main.jsp";
			  			window.location.href = url;
			  		}
			  		else{
			  				var msg = json.rtMsrg;
			  				$('#pwd').focus();
			  				$('#pwd').val('');
			  				$.messager.alert('提示：',msg);
			  		}
				}
			});
	  } catch (e){
	    alert('服务器连接中断');
	  }
	}
	
	
	function doInit(){
	  if (getCookie('userName')){
		  $('#userName').val(getCookie('userName'));
	      $('#pwd').focus();
	  }
	  else{
	    $('#userName').focus();
	  }
	  $("#pwd").keypress(function(e) { 
    	// 回车键事件 
     	  if(e.which == 13) { 
   			doLogin();
       		} 
   		}); 
	  /**
	if(isFF()){
  		return;
  	}
 	 $.messager.show({
		title:'提示',
		msg:'为了体验最佳的使用效果，建议您使用<a href=\'http://www.firefox.com.cn/\' target=\'_target\'><font color=\'green\'><strong>火狐浏览器</strong></font></a>',
		showType:'show',
		height:200,
		timeout:0
	});
 	 **/
}

function isFF(){
	return navigator.userAgent.indexOf("Firefox")!=-1;
}
	
	/**
	 * 设置cookie
	 */
	function setCookie(name,value){
	  var Days = 30;
	  var exp  = new Date();
	  exp.setTime(exp.getTime() + Days*24*60*60*1000);
	  document.cookie = name + "="+ escape (value) + ";path=/;expires=" + exp.toGMTString();
	}
	
	/**
	 * 读取cookie
	 */
	function getCookie(name){
	  
	  var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
	  if (arr != null){
	    return unescape(arr[2]);
	  }
	  else{
	    return null;
	  }
	  return null;
	}

</script>
</head>

<body onload="doInit()">

<div style="background-image:url(<%=contextPath %>/public/images/admin_login.png); width:500px; height:200px; margin-top:150px;margin-left:155px;">
    <table width="500" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="250">&nbsp;</td>
        <td colspan="2">&nbsp;</td>
      </tr>
      <tr>
        <td width="250">&nbsp;</td>
        <td colspan="2">&nbsp;</td>
      </tr>
      <tr>
        <td height="40"><div align="right" class="STYLE1">用户名：</div></td>
        <td height="40" colspan="2"><input type="text" id="userName" name="userName" style="height:25px; width:200px; " placeholder="请输入用户名"/></td>
      </tr>
      <tr>
        <td height="40"><div align="right" class="STYLE1">密&nbsp; 码：</div></td>
        <td height="40" colspan="2"><input type="password"  id="pwd" name="pwd" style="height:25px; width:200px;" placeholder="请输入密码"/></td>
      </tr>
      <tr>
        <td height="40">&nbsp;</td>
        <td height="40" colspan="2"><input type="button" onclick="doLogin();" value="" style="width:130px; height:30px; background-image:url(<%=contextPath %>/public/images/admin_login_button.png); border:0; background-color: transparent; cursor: pointer"/></td>
      </tr>
    </table>
</div>

</body>
</html>
